﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace CuteRibs.MVVMLib.ValueConverters
{
	public class UriToImageBrushConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			ImageBrush brush = new ImageBrush();
			Uri uri;

			if (value is string)
			{
				uri = new Uri((string)value, UriKind.RelativeOrAbsolute);
			}
			else
			{
				uri = (Uri)value;
			}

			brush.ImageSource = new BitmapImage(uri);
			return brush;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
